# ./configure --with-libraries=all --with-icu --prefix=/usr/lib
# make&&sudo make install

# Program info
PROGRAM = newmoon
OPTIONS =
SHARED = ./shared/
SHARED_OBJS = compat.o debugout.o mathx.o
SHARED_SRCS = $(SHARED)compat.cpp $(SHARED)debugout.c $(SHARED)mathx.cpp
OBJS = $(SHARED_OBJS) gui/cWindow.o gui/cDrawBox.o gui/cImgBuf.o gui/cMainWindow.o gui/cPaletteWindow.o gui/cTileWindow.o gui/cMap16Window.o cGFXBuf.o cCompressor.o cCompressorLcLz2.o cCompressor3BPP.o cROMFile.o cSNESPointer.o cSMWObject.o cLevel.o main.o
OTHER_DEP =
LIBS = -L/usr/local/lib `pkg-config --libs gtk+-2.0`
#todo: if it's possible to get 'date' to output * or <<, we can avoid calling it 3 times
DAY = `date +%-d`
MONTH = `date +%-m`
YEAR = `date +%-y`
BUILD_INDEX = 0
BUILD_ID = "((BUILD_YEAR << 13) | (BUILD_MONTH << 9) | (BUILD_DAY << 4) | BUILD_INDEX)"

CMDLINE = $(PROGRAM)

LIBPATH = /usr/lib/
DELETE = rm -rf
#export PATH := $(MINGW)bin:$(PATH)
OS = LINUX

# etc
CXX = g++
CXXFLAGS = -O3 -Wall -I$(SHARED) -D$(OS) -DBUILD_DAY=$(DAY) -DBUILD_MONTH=$(MONTH) -DBUILD_YEAR=$(YEAR) -DBUILD_INDEX=$(BUILD_INDEX) -DBUILD_ID=$(BUILD_ID) -DGTK_MULTIHEAD_SAFE=1 `pkg-config --cflags gtk+-2.0`
LD = $(CXX)
LDFLAGS =
COMPILE = $(CXX) $(CXXFLAGS) -c

all: $(PROGRAM)
	@echo @@ START @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	@./$(CMDLINE)
	@echo @@ END @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	
noexec: $(PROGRAM)
	
.PHONY : all noexec clean

$(PROGRAM): $(OBJS)
	$(LD) $(LDFLAGS) -o $(PROGRAM) $(OBJS) $(LIBS) $(OPTIONS)
	
%.o: %.c $(OTHER_DEP)
	$(COMPILE) $(<) -o $(@)
	
$(SHARED_OBJS): $(SHARED_SRCS)
	$(COMPILE) $(^)
	
#this is stupidly complex for a simple recursive delete V_v
clean:
	$(DELETE) $(PROGRAM)
	find . -name "*.o" -exec rm -f {} \;
	find . -name "*.log" -exec rm -f {} \;
